<template>
	<view class="home">
		<view class="nav">
			<u-subsection :list="list" :current="0" :animation="true" mode="button" active-color="#fff" bgColor="#fff"
			 buttonColor="#00C2FF" @change="change" :active-item-style="activeStyle"></u-subsection>
		</view>

		<view v-if="current === 0">
			<uni-collapse>
				<!-- <image src="../../static/icon/Error.png" mode=""></image> -->
				<uni-collapse-item :title="item.give_item" v-if="item.select_paoshou == User_number && (item.whether_finished_paoshou == 0)"
				 v-for="(item,index) in All_Task" :key="index" thumb="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592216723318&di=529d68eae45f4d5bb138eb57911f6dd7&imgtype=0&src=http%3A%2F%2Fimg3.imgtn.bdimg.com%2Fit%2Fu%3D1597981878%2C1165503325%26fm%3D214%26gp%3D0.jpg">
					<view style="padding: 30rpx;">
						<view class="">取件码:{{item.get_code}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">快递大小:{{item.size}}</view>
						<view class="">发布者:{{item.name}} (快递类型:{{item.type}})</view>
						<view class="">取件地:{{item.take_item}}</view>
						<view class="">发布者备注:{{item.Notes}}</view>
					</view>
					<view class="flex-row">
						<button class="btn success" type="warn" @click="Navigation(item.id,item.publisher_number)">完成</button>
						<button class="btn infobtn" type="primary"  @click="nav(item.id)">详情</button>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>

		<view class="Tips" v-show="show === 1 && current === 0">
			你还未接过订单哦~
		</view>


		<view v-if="current === 1">
			<view class="history" v-for="(item,index) in list_evaluate" :key="index" v-if="item.paoshou == User_number">
				<view class="" style="text-align: center;font-weight: bold;">{{item.name}}({{item.User}})</view>
				<u-read-more :toggle="true" show-height="120">
					<rich-text :nodes="item.Eval"></rich-text>
				</u-read-more>
			</view>

			<view class="Tips" v-show="Eval_show === 1">
				你未接到任何评论哦~
			</view>
		</view>

		<view v-if="current === 2">
			<u-tabs-swiper ref="tabs" :list="List_history" :is-scroll="false" @change="NAV" :current="Current"></u-tabs-swiper>

			<uni-collapse accordion="true" v-if="Current === 0">
				<uni-collapse-item :title="item.name" v-for="(item,index) in All_Task" :key="index" v-if="item.select_paoshou == User_number && (item.whether_finished_paoshou == 1)">
					<view style="padding: 30rpx;">
						<view class="">取件码:{{item.get_code}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">快递大小:{{item.size}}</view>
						<view class="">发布者:{{item.name}} (快递类型:{{item.type}})</view>
						<view class="">取件地:{{item.take_item}}</view>
						<view class="">发布者备注:{{item.Notes}}</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>

			<uni-collapse accordion="true" v-if="Current === 1">

				<u-subsection :list="list_FoodOrPrint_history" :current_FoodPrint="0" :animation="true" mode="button" active-color="#ff9900"
				 bgColor="#ECF5FF" buttonColor="#19BE6B" @change="Change_FoodPrint"></u-subsection>

				<uni-collapse-item :title="item.name" v-for="(item,index) in BoxInfo" :key="index" v-if="item.select_paoshou == User_number && (item.whether_finished == 1) && current_FoodPrint == 0">
					<view style="padding: 30rpx;">
						<view class="">发布者:{{item.name}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">买饭(物)地点:{{item.intro}}</view>
						<view class="">送达时间(最迟):{{item.time}}</view>
					</view>
				</uni-collapse-item>

				<uni-collapse-item :title="item.name" v-for="(item,index) in PrintInfo" :key="index" v-if="item.select_paoshou == User_number && (item.whether_finished == 1) && current_FoodPrint == 1">
					<view style="padding: 30rpx;">
						<view class="">电话:{{item.telephone_number}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">打印地点:{{item.get_Address}}</view>
						<view class="">送达地点:{{item.give_Address}}</view>
						<view class="">备注:{{item.Notes}}</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>

		<view class="Tips" v-show="show_history === 1 && current === 2 && Current === 0">
			你未接过任何订单哦~
		</view>

		<view class="Tips" v-show="History_BoxOrFood === 1 && current === 2  && Current === 1 && current_FoodPrint == 0">
			你未接过任何订单哦~
		</view>

		<view class="Tips" v-show="History_Print === 1 && current === 2  && Current === 1 && current_FoodPrint == 1">
			你未接过任何订单哦~
		</view>

		<view v-if="current === 3">
			<u-tabs-swiper ref="tabs" :list="List_history_Order" :is-scroll="false" @change="NAV_order" :current="CURRENT"></u-tabs-swiper>

			<uni-collapse accordion="true" v-if="CURRENT === 0">
				<!--  -->
				<uni-collapse-item :title="item.name" v-for="(item,index) in All_Task" :key="index" v-if="item.publisher_number == User_number && (item.whether_finished_paoshou == 1)">>
					<view style="padding: 30rpx;">
						<view class="">取件码:{{item.get_code}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">快递大小:{{item.size}}</view>
						<view class="">发布者:{{item.name}} (快递类型:{{item.type}})</view>
						<view class="">取件地:{{item.take_item}}</view>
						<view class="">发布者备注:{{item.Notes}}</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>

			<uni-collapse accordion="true" v-if="CURRENT === 1">

				<u-subsection :list="list_FoodOrPrint_history_release" :current_FoodPrint_release="0" :animation="true" mode="button"
				 active-color="#ff9900" bgColor="#ECF5FF" buttonColor="#19BE6B" @change="Change_FoodPrint_release"></u-subsection>

				<uni-collapse-item :title="item.name" v-for="(item,index) in BoxInfo" :key="index" v-if="item.number == User_number && (item.whether_finished == 1) && current_FoodPrint_release == 0">
					<view style="padding: 30rpx;">
						<view class="">买饭(物)地点:{{item.intro}}</view>
						<view class="">发布者:{{item.name}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">送达时间(最迟):{{item.time}}</view>
					</view>
				</uni-collapse-item>

				<uni-collapse-item :title="item.name" v-for="(item,index) in PrintInfo" :key="index" v-if="item.number == User_number && (item.whether_finished == 1) && current_FoodPrint_release == 1">
					<view style="padding: 30rpx;">
						<view class="">打印地点:{{item.get_Address}}</view>
						<view class="">送达地点:{{item.give_Address}}</view>
						<view class="">电话:{{item.telephone_number}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">备注:{{item.Notes}}</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>


		<view class="Tips" v-show="History_rekease === 1 && current === 3 && CURRENT === 0">
			还未发布任何订单哦~
		</view>

		<view class="Tips" v-show="History_rekeaseBox === 1 && current === 3 && CURRENT === 1 && current_FoodPrint_release === 0">
			还未发布任何订单哦~
		</view>

		<view class="Tips" v-show="History_rekeasePrint === 1 && current === 3 && CURRENT === 1 && current_FoodPrint_release === 1">
			还未发布任何订单哦~
		</view>

		<view v-if="current === 4">

			<u-tabs-swiper ref="tabs" :list="list_FoodOrPrint" :is-scroll="false" @change="Food_Or_Print" :current="current_FoodOrPrint"></u-tabs-swiper>

			<uni-collapse v-if="current_FoodOrPrint == 0">
				<uni-collapse-item :title="item.give_Address" v-if="item.select_paoshou == User_number && (item.whether_finished == 0)"
				 v-for="(item,index) in BoxInfo" :key="index" thumb="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592216723318&di=529d68eae45f4d5bb138eb57911f6dd7&imgtype=0&src=http%3A%2F%2Fimg3.imgtn.bdimg.com%2Fit%2Fu%3D1597981878%2C1165503325%26fm%3D214%26gp%3D0.jpg">
					<view style="padding: 30rpx;">
						<view class="">买饭(物)地点:{{item.intro}}</view>
						<view class="">发布者:{{item.name}}</view>
						<view class="">电话:{{item.telephone}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">送达时间(最迟):{{item.time}}</view>
					</view>
					<view style="flex-row">
						<button type="warn" class="btn order-success" @click="Navigation_BoxOrFood(item.id,item.number)">订单完成</button>
					</view>
				</uni-collapse-item>
			</uni-collapse>

			<uni-collapse v-if="current_FoodOrPrint == 1">
				<uni-collapse-item :title="item.give_Address" v-if="item.select_paoshou == User_number && (item.whether_finished == 0)"
				 v-for="(item,index) in PrintInfo" :key="index" thumb="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592216723318&di=529d68eae45f4d5bb138eb57911f6dd7&imgtype=0&src=http%3A%2F%2Fimg3.imgtn.bdimg.com%2Fit%2Fu%3D1597981878%2C1165503325%26fm%3D214%26gp%3D0.jpg">
					<view style="padding: 30rpx;">
						<view class="">打印地点:{{item.get_Address}}</view>
						<view class="">发布者:{{item.name}}</view>
						<view class="">电话:{{item.telephone_number}}</view>
						<view class="">金额:{{item.money}}元</view>
						<view class="">备注:{{item.Notes}}</view>
					</view>
					<view style="flex-row">
						<button type="warn"class="btn order-success" @click="Print_nav(item.id,item.number)">订单完成</button>
					</view>
				</uni-collapse-item>
			</uni-collapse>

			<view class="Tips" v-show="BoxOrFood_order === 1 && current === 4 && current_FoodOrPrint == 0">
				还未接手任何订单哦~
			</view>

			<view class="Tips" v-show="Print_order === 1 && current === 4 && current_FoodOrPrint == 1">
				还未接手任何订单哦~
			</view>
		</view>
	</view>
</template>

<script>
	import uniCollapse from '@/pagesD/uni-collapse/uni-collapse.vue'
	import uniCollapseItem from '@/pagesD/uni-collapse-item/uni-collapse-item.vue'
	export default {
		data() {
			return {
				activeStyle: {
					'border-radius': '0'
				},
				list: [{
						name: '接单(快递)'
					},
					{
						name: '用户评价'
					},
					{
						name: '历史接单'
					},
					{
						name: '历史发布'
					},
					{
						name: '接单(饭物)'
					}
				],
				list_FoodOrPrint_history: [{
						name: '饭或零食'
					},
					{
						name: '打印'
					},
				],
				list_FoodOrPrint_history_release: [{
						name: '饭或零食'
					},
					{
						name: '打印'
					},
				],
				current: 0,
				current_FoodPrint: 0,
				current_FoodPrint_release: 0,
				list_evaluate: [],
				User_number: '',
				All_Task: [],
				show: 1,
				show_history: 1,
				History_rekease: 1,
				History_rekeaseBox: 1,
				History_rekeasePrint: 1,
				History_BoxOrFood: 1,
				History_Print: 1,
				BoxOrFood_order: 1,
				Print_order: 1,
				BoxInfo: [{
					intro: '1',
					name: '1',
					telephone: '2',
					money: '3',
					time: '1'
				}],
				PrintInfo: [],
				List_history: [{
					name: '快递(历史接单)'
				}, {
					name: '物食(历史接单)'
				}],
				Current: 0,
				List_history_Order: [{
					name: '快递(历史发布)'
				}, {
					name: '物食(历史发布)'
				}],
				CURRENT: 0,
				current_FoodOrPrint: 0,
				list_FoodOrPrint: [{
					name: '饭或零食'
				}, {
					name: '打印'
				}],
				Eval_show: 1
			}
		},
		methods: {
			change(e) {
				this.current = e;
				console.log(this.current);
				// console.log(e)
			},
			Change_FoodPrint(e) {
				this.current_FoodPrint = e;
			},
			Change_FoodPrint_release(e) {
				this.current_FoodPrint_release = e;
			},
			async get_message() {
				this.show = 1;
				this.show_history = 1;
				this.History_rekease = 1;
				const res = await this.$myRequest({
					url: 'getTaskInfo'
				})
				if (res.data.code != 0) {
					return;
				}
				this.All_Task = res.data.message;
				console.log(this.All_Task)
				for (let i = 0; i < this.All_Task.length; i++) {
					if (this.All_Task[i].select_paoshou == this.User_number && this.All_Task[i].whether_finished_order == 0) {
						this.show = 0;
					}

					if (this.All_Task[i].whether_finished_paoshou == 1 && this.All_Task[i].select_paoshou == this.User_number) {
						this.show_history = 0;
					}

					if (this.All_Task[i].publisher_number == this.User_number && this.All_Task[i].whether_finished_order == 1) {
						this.History_rekease = 0;
					}
				}
			},
			nav(index) {
				for (let i = 0; i < this.All_Task.length; i++) {
					if (this.All_Task[i].id == index) {
						uni.navigateTo({
							url: `../navs/navs?now_x=${this.All_Task[i].position.x}&now_y=${this.All_Task[i].position.y}&give_x=${this.All_Task[i].give_position.x}&give_y=${this.All_Task[i].give_position.y}`
						})
					}
				}
			},
			async Finish(id, number) {
				const res = await this.$myRequest({
					url: `finished_Task?id=${id}&number=${number}`
				})
				console.log(res)
				if (res.data.code == 0) {
					this.get_message();
				} else {
					return;
				}
			},
			Navigation(id, number) {
				uni.showModal({
					title: '温馨提醒',
					content: '是否完成?',
					success: (res) => {
						if (res.confirm) {
							this.Finish(id, number);
						} else if (res.cancel) {
							console.log('用户点击了取消');
						}
					}
				})
			},
			async GetBoxMessage() {
				this.History_rekeaseBox = 1;
				this.History_BoxOrFood = 1;
				this.BoxOrFood_order = 1;
				const res = await this.$myRequest({
					url: 'GetTaskMessage'
				})
				if (res.data.code == 0) {
					this.BoxInfo = res.data.message;
					console.log(this.BoxInfo, '新')

					for (let i = 0; i < this.BoxInfo.length; i++) {
						if (this.BoxInfo[i].select_paoshou == this.User_number && this.BoxInfo[i].whether_finished == 0) {
							this.BoxOrFood_order = 0;
						}

						if (this.BoxInfo[i].select_paoshou == this.User_number && this.BoxInfo[i].whether_finished == 1) {
							this.History_BoxOrFood = 0;
						}

						if (this.BoxInfo[i].number == this.User_number && this.BoxInfo[i].whether_finished == 1) {
							this.History_rekeaseBox = 0;
						}
					}
				}
			},
			NAV(index) {
				this.Current = index;
			},
			NAV_order(index) {
				console.log(index)
				this.CURRENT = index;
				console.log(this.CURRENT, '是否')
			},
			Food_Or_Print(index) {
				this.current_FoodOrPrint = index;
			},
			async Finish_BoxOrFood(id, number) {
				console.log(id, number)
				const res = await this.$myRequest({
					url: `Finish_BoxOrFood?id=${id}&number=${number}`
				})
				if (res.data.code == 0) {
					this.GetBoxMessage();
				} else {
					return;
				}
			},
			async Finish_PrintTask(id, number) {
				console.log(id, number, '测试')
				const res = await this.$myRequest({
					url: `Finish_PrintTask?id=${id}&number=${number}`
				})
				console.log(res, '测试1')
				if (res.data.code == 0) {
					this.GetPrintInfoMessage()
				} else {
					return;
				}
			},
			Navigation_BoxOrFood(id, number) {
				uni.showModal({
					title: '温馨提醒',
					content: '是否完成?',
					success: (res) => {
						if (res.confirm) {
							this.Finish_BoxOrFood(id, number);
						} else if (res.cancel) {
							console.log('用户点击了取消');
						}
					}
				})
			},
			Print_nav(id, number) {
				uni.showModal({
					title: '温馨提醒',
					content: '是否完成?',
					success: (res) => {
						if (res.confirm) {
							this.Finish_PrintTask(id, number);
						}
					}
				})
			},
			async GetPrintInfoMessage() {
				this.Print_order = 1;
				this.History_rekeasePrint = 1;
				this.History_Print = 1;
				const res = await this.$myRequest({
					url: 'GetPrintMessage'
				})
				if (res.data.code == 0) {
					this.PrintInfo = res.data.message;
					console.log(this.PrintInfo)
					for (let i = 0; i < this.PrintInfo.length; i++) {
						if (this.PrintInfo[i].select_paoshou == this.User_number && this.PrintInfo[i].whether_finished == 0) {
							this.Print_order = 0;
						}

						if (this.PrintInfo[i].select_paoshou == this.User_number && this.PrintInfo[i].whether_finished == 1) {
							this.History_Print = 0;
						}

						if (this.PrintInfo[i].number == this.User_number && this.PrintInfo[i].whether_finished == 1) {
							this.History_rekeasePrint = 0;
						}
					}
				}

			},
			async GetEvalMessage() {
				const res = await this.$myRequest({
					url: 'GetEvalMessage'
				})
				if (res.data.code == 0) {
					this.list_evaluate = res.data.message;
					console.log(this.list_evaluate);
				}

				for (let i = 0; i < this.list_evaluate.length; i++) {
					if (this.list_evaluate[i].paoshou == this.User_number) {
						this.Eval_show = 0;
						break;
					}
				}
			}
		},
		components: {
			uniCollapse,
			uniCollapseItem
		},
		onLoad(options) {
			this.get_message();
			this.GetBoxMessage();
			this.GetPrintInfoMessage();
			this.GetEvalMessage();

			this.User_number = options.number;
		}
	}
</script>

<style lang="scss">
	.home {
		width: 100%;
		
		.flex-row{
			display: flex;
		}
		.btn{
			width: 40%;
			font-size: 28rpx;
			height: 90rpx;
			line-height: 90rpx;
			border-radius: 45rpx;
			margin-bottom: 30rpx;
			&.success{
				background-color: $main-color;
			}
			&.infobtn{
			}
			&.order-success{
				width: 90%;
				background-color: $main-color;
			}
		}
		.content {
			font-size: 18px;
			border: 1px solid #C0C0C0;
			display: flex;
			
			.content_itemOne {
				margin-left: 10px;
				width: 300px;
				height: 40px;
				line-height: 40px;
			}

			.content_itemTwo {
				width: 75px;
				height: 40px;
				line-height: 40px;
				text-align: center;
				color: #FFFFFF;
				background: green;
				border-radius: 10px;
			}
		}

		.history {
			border: 1px solid #C0C4CC;
			padding: 8px;
		}

		.Tips {
			font-size: 30px;
			width: 100%;
			height: 300px;
			line-height: 300px;
			text-align: center;
			color: #C8C7CC;
		}
	}
</style>
